package com.sky.controller.admin;

import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api("分类管理相关接口")
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result page(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("员工分页：{}", categoryPageQueryDTO);
        PageResult result = categoryService.page(categoryPageQueryDTO);
        return Result.success(result);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用")
    public Result StartOrStop(@PathVariable String status,Long id){
        log.info("当前状态和Id是：{}，{}", status, id);
        categoryService.startOrStop(status,id);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改分类")
    public Result<Category> Update(@RequestBody CategoryDTO categoryDTO) {
        Category category = categoryService.update(categoryDTO);
        return Result.success(category);
    }

    @PostMapping
    @ApiOperation("新增分类")
    public Result<Category> Add(@RequestBody Category category) {
        log.info("菜单种类参数{}", category);
        categoryService.addCategory(category);
        return Result.success();
    }

    @DeleteMapping
    public Result<Category> Delete( int id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }

    @GetMapping("list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(int type){
        List<Category> categoryList = categoryService.list();
        return Result.success(categoryList);
    }
}
